<?php
/**
 *    @version [ Masterton ]
 *    @package hwdVideoShare
 *    @copyright (C) 2007 - 2009 Highwood Design
 *    @license Creative Commons Attribution-Non-Commercial-No Derivative Works 3.0 Unported Licence
 *    @license http://creativecommons.org/licenses/by-nc-nd/3.0/
 */
defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );

global $mainframe, $option, $smartyvs;

if (!file_exists(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS)) {
	echo "<div style=\"border:1px solid #c30;color:#c30;margin: 0 0 5px 0;padding: 5px;font-weight: bold;text-align:left;text-align:center;\">The hwdVideoShare component is not installed, you can not use this module.</div>"; return;
}

$db =& JFactory::getDBO();
$my = & JFactory::getUser();
require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'helpers'.DS.'initialise.php');
hwdvsInitialise::coreRequire();
hwdvsInitialise::language();
hwdvsInitialise::template();
hwdvsInitialise::mysqlQuery();
hwdvsInitialise::definitions();

if (@_HWD_VS_PLUGIN_COMPS !== 214) {
	echo "<div style=\"border:1px solid #c30;color:#c30;margin: 0 0 5px 0;padding: 5px;font-weight: bold;text-align:left;text-align:center;\">This module is not compatible with your version of hwdVideoShare.</div>"; return;
}

$c = hwd_vs_Config::get_instance();
$video_id = JRequest::getInt( 'video_id', null );

/* Security Note: These values are auto-sanitized by mosGetParam() */
$hwdvids_params['style']	 		= (int)$params->get( 'style', '1');

$hwdvids_params['malignment']	 	= (int)$params->get( 'malignment', '1');
$hwdvids_params['talignment']	 	= (int)$params->get( 'talignment', '2');

$hwdvids_params['mod_hwd_itemid'] 	= (int)$params->get( 'mod_hwd_itemid', '0');
$hwdvids_params['mod_cb_itemid'] 	= (int)$params->get( 'mod_cb_itemid', '0');
$hwdvids_params['mod_width'] 		= $params->get( 'mod_width', '100%');
$hwdvids_params['thumb_width'] 		= (int)$params->get( 'thumb_width', '120');
$hwdvids_params['novtd'] 			= (int)$params->get( 'novtd', '3');
$hwdvids_params['novpr'] 			= (int)$params->get( 'novpr', '3');
$hwdvids_params['novtl'] 			= (int)$params->get( 'novtl', '30');
$hwdvids_params['autoplay'] 		= (int)$params->get( 'autoplay', '1');

$hwdvids_params['starttab'] 		= (int)$params->get( 'starttab', '1');
$hwdvids_params['showmvtd'] 		= (int)$params->get( 'showmvtd', '1');
$hwdvids_params['showmvtw'] 		= (int)$params->get( 'showmvtw', '1');
$hwdvids_params['showmvtm'] 		= (int)$params->get( 'showmvtm', '1');
$hwdvids_params['showmvat'] 		= (int)$params->get( 'showmvat', '1');
$hwdvids_params['showmptd'] 		= (int)$params->get( 'showmptd', '1');
$hwdvids_params['showmptw'] 		= (int)$params->get( 'showmptw', '1');
$hwdvids_params['showmptm'] 		= (int)$params->get( 'showmptm', '1');
$hwdvids_params['showmpat'] 		= (int)$params->get( 'showmpat', '1');
$hwdvids_params['showmftd'] 		= (int)$params->get( 'showmftd', '1');
$hwdvids_params['showmftw'] 		= (int)$params->get( 'showmftw', '1');
$hwdvids_params['showmftm'] 		= (int)$params->get( 'showmftm', '1');
$hwdvids_params['showmfat'] 		= (int)$params->get( 'showmfat', '1');

$hwdvids_params['trunc_title'] 		= (int)$params->get( 'trunc_title', '');
$hwdvids_params['trunc_descr'] 		= (int)$params->get( 'trunc_descr', '');
$hwdvids_params['showtt'] 		    = (int)$params->get( 'showtt', '0');

$hwdvids_params['showtitle'] 		= (int)$params->get( 'showtitle', '1');
$hwdvids_params['showcategory'] 	= (int)$params->get( 'showcategory', '1');
$hwdvids_params['showdescription'] 	= (int)$params->get( 'showdescription', '1');
$hwdvids_params['showrating'] 		= (int)$params->get( 'showrating', '1');
$hwdvids_params['shownov'] 			= (int)$params->get( 'shownov', '1');
$hwdvids_params['showduration'] 	= (int)$params->get( 'showduration', '1');
$hwdvids_params['showuser'] 		= (int)$params->get( 'showuser', '1');
$hwdvids_params['showtime'] 		= (int)$params->get( 'showtime', '1');
$hwdvids_params['timeformat'] 		= $params->get( 'timeformat', 'm');

if ($hwdvids_params['mod_hwd_itemid'] == 0) {
	$hwdvids_params['mod_hwd_itemid'] = hwd_vs_tools::generateValidItemid();
}

if ($hwdvids_params['showtt'] == 0) {
	$tooltip = false;
} else {
	$tooltip = true;
}

$template_folder = $mainframe->getUserState( "com_hwdvideoshare.template_folder", '' );
$template_element = $mainframe->getUserState( "com_hwdvideoshare.template_element", '' );
if (!empty($template_folder) && !empty($template_element)) {

	$c->hwdvids_template_path = $template_folder;
	$c->hwdvids_template_file = $template_element;

}

$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.JURI::root( true ).'/plugins/hwdvs-template/'.$c->hwdvids_template_file.'/js/tabber.js"></script>');
$mainframe->addCustomHeadTag('<link rel="stylesheet" type="text/css" href="'.JURI::root( true ).'/modules/mod_hwd_vs_xml_datalists/mod_hwd_vs_xml_datalists/core.css"/>');

if ($hwdvids_params['malignment'] == 2) {
	$mainframe->addCustomHeadTag('<style type="text/css">ul.tabbernav li { display:block!important; } dl.tabs dt { padding: 4px 2px!important; }</style>');
}

require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'helpers'.DS.'js.php');

jimport('joomla.html.pane');

if ($hwdvids_params['starttab']==1 || $hwdvids_params['starttab']==2 || $hwdvids_params['starttab']==3 || $hwdvids_params['starttab']==4) {
	$pane =& JPane::getInstance('tabs', array('startOffset'=>0));
} else if ($hwdvids_params['starttab']==5 || $hwdvids_params['starttab']==6 || $hwdvids_params['starttab']==7 || $hwdvids_params['starttab']==8) {
	$pane =& JPane::getInstance('tabs', array('startOffset'=>1));
} else if ($hwdvids_params['starttab']==9 || $hwdvids_params['starttab']==10 || $hwdvids_params['starttab']==11 || $hwdvids_params['starttab']==12) {
	$pane =& JPane::getInstance('tabs', array('startOffset'=>2));
}

$startpane = $pane->startPane( 'hwdvs-xml-pane' );
$endpane = $pane->endPane();
$endtab = $pane->endPanel();
$smartyvs->assign("startpane", $startpane);
$smartyvs->assign("endpane", $endpane);
$smartyvs->assign("endtab", $endtab);
if ($hwdvids_params['malignment'] == 2)
{
	$starttab_mostviewed = $pane->startPanel("Viewed", 'panel-MV' );
	$starttab_mostpopular = $pane->startPanel("Popular", 'panel-MP' );
	$starttab_mostfavoured = $pane->startPanel("Favoured", 'panel-MF' );
}
else
{
	$starttab_mostviewed = $pane->startPanel(_HWDVIDS_MVAT, 'panel-MV' );
	$starttab_mostpopular = $pane->startPanel(_HWDVIDS_MPAT, 'panel-MP' );
	$starttab_mostfavoured = $pane->startPanel(_HWDVIDS_MFAT, 'panel-MF' );
}
$smartyvs->assign("starttab_mostviewed", $starttab_mostviewed);
$smartyvs->assign("starttab_mostpopular", $starttab_mostpopular);
$smartyvs->assign("starttab_mostfavoured", $starttab_mostfavoured);

// parse xml playlists
require_once(JPATH_SITE.DS.'components'.DS.'com_hwdvideoshare'.DS.'xml'.DS.'xmlparse.class.php');
$parser = new HWDVS_xmlParse();

$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.JURI::root( true ).'/components/com_hwdvideoshare/assets/js/icarousel.js"></script> ');
require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'helpers'.DS.'carousel.php');

if ($hwdvids_params['showmvtd'] == 1) {
	$mostviewed_today = $parser->parse("mostviewed_today");
	if ($hwdvids_params['style'] !== 1 && count($mostviewed_today) > 0) {
		array_splice($mostviewed_today, $hwdvids_params['novtd']);
	}
	$rows_mostviewed_today = hwd_vs_tools::generateVideoListFromXml($mostviewed_today, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostviewed_today", $rows_mostviewed_today);
	if (count($rows_mostviewed_today) > 0) {
		$starttab_mostviewed_today = $pane->startPanel(_HWDVIDS_MVTD, 'panel-MVTD' );
		$smartyvs->assign("print_mvtd", 1);
		$smartyvs->assign("starttab_mostviewed_today", $starttab_mostviewed_today);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostviewed_today', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmvtw'] == 1) {
	$mostviewed_thisweek = $parser->parse("mostviewed_thisweek");
	if ($hwdvids_params['style'] !== 1 && count($mostviewed_thisweek) > 0) {
		array_splice($mostviewed_thisweek, $hwdvids_params['novtd']);
	}
	$rows_mostviewed_thisweek = hwd_vs_tools::generateVideoListFromXml($mostviewed_thisweek, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostviewed_thisweek", $rows_mostviewed_thisweek);
	if (count($rows_mostviewed_thisweek) > 0) {
		$starttab_mostviewed_thisweek = $pane->startPanel(_HWDVIDS_MVTW, 'panel-MVTW' );
		$smartyvs->assign("print_mvtw", 1);
		$smartyvs->assign("starttab_mostviewed_thisweek", $starttab_mostviewed_thisweek);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostviewed_thisweek', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmvtm'] == 1) {
	$mostviewed_thismonth = $parser->parse("mostviewed_thismonth");
	if ($hwdvids_params['style'] !== 1 && count($mostviewed_thismonth) > 0) {
		array_splice($mostviewed_thismonth, $hwdvids_params['novtd']);
	}
	$rows_mostviewed_thismonth = hwd_vs_tools::generateVideoListFromXml($mostviewed_thismonth, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostviewed_thismonth", $rows_mostviewed_thismonth);
	if (count($rows_mostviewed_thismonth) > 0) {
		$starttab_mostviewed_thismonth = $pane->startPanel(_HWDVIDS_MVTM, 'panel-MVTM' );
		$smartyvs->assign("print_mvtm", 1);
		$smartyvs->assign("starttab_mostviewed_thismonth", $starttab_mostviewed_thismonth);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostviewed_thismonth', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmvat'] == 1) {
	$mostviewed_alltime = $parser->parse("mostviewed_alltime");
	if ($hwdvids_params['style'] !== 1 && count($mostviewed_alltime) > 0) {
		array_splice($mostviewed_alltime, $hwdvids_params['novtd']);
	}
	$rows_mostviewed_alltime = hwd_vs_tools::generateVideoListFromXml($mostviewed_alltime, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostviewed_alltime", $rows_mostviewed_alltime);
	if (count($rows_mostviewed_alltime) > 0) {
		$starttab_mostviewed_alltime = $pane->startPanel(_HWDVIDS_MVAT, 'panel-MVAT' );
		$smartyvs->assign("print_mvat", 1);
		$smartyvs->assign("starttab_mostviewed_alltime", $starttab_mostviewed_alltime);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostviewed_alltime', $hwdvids_params);
		}
	}
}

if ($hwdvids_params['showmptd'] == 1) {
	$mostpopular_today = $parser->parse("mostpopular_today");
	if ($hwdvids_params['style'] !== 1 && count($mostpopular_today) > 0) {
		array_splice($mostpopular_today, $hwdvids_params['novtd']);
	}
	$rows_mostpopular_today = hwd_vs_tools::generateVideoListFromXml($mostpopular_today, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostpopular_today", $rows_mostpopular_today);
	if (count($rows_mostpopular_today) > 0) {
		$starttab_mostpopular_today = $pane->startPanel(_HWDVIDS_MPTD, 'panel1' );
		$smartyvs->assign("print_mptd", 1);
		$smartyvs->assign("starttab_mostpopular_today", $starttab_mostpopular_today);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostpopular_today', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmptw'] == 1) {
	$mostpopular_thisweek = $parser->parse("mostpopular_thisweek");
	if ($hwdvids_params['style'] !== 1 && count($mostpopular_thisweek) > 0) {
		array_splice($mostpopular_thisweek, $hwdvids_params['novtd']);
	}
	$rows_mostpopular_thisweek = hwd_vs_tools::generateVideoListFromXml($mostpopular_thisweek, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostpopular_thisweek", $rows_mostpopular_thisweek);
	if (count($rows_mostpopular_thisweek) > 0) {
		$starttab_mostpopular_thisweek = $pane->startPanel(_HWDVIDS_MPTW, 'panel1' );
		$smartyvs->assign("print_mptw", 1);
		$smartyvs->assign("starttab_mostpopular_thisweek", $starttab_mostpopular_thisweek);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostpopular_thisweek', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmptm'] == 1) {
	$mostpopular_thismonth = $parser->parse("mostpopular_thismonth");
	if ($hwdvids_params['style'] !== 1 && count($mostpopular_thismonth) > 0) {
		array_splice($mostpopular_thismonth, $hwdvids_params['novtd']);
	}
	$rows_mostpopular_thismonth = hwd_vs_tools::generateVideoListFromXml($mostpopular_thismonth, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostpopular_thismonth", $rows_mostpopular_thismonth);
	if (count($rows_mostpopular_thismonth) > 0) {
		$starttab_mostpopular_thismonth = $pane->startPanel(_HWDVIDS_MPTM, 'panel1' );
		$smartyvs->assign("print_mptm", 1);
		$smartyvs->assign("starttab_mostpopular_thismonth", $starttab_mostpopular_thismonth);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostpopular_thismonth', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmpat'] == 1) {
	$mostpopular_alltime = $parser->parse("mostpopular_alltime");
	if ($hwdvids_params['style'] !== 1 && count($mostpopular_alltime) > 0) {
		array_splice($mostpopular_alltime, $hwdvids_params['novtd']);
	}
	$rows_mostpopular_alltime = hwd_vs_tools::generateVideoListFromXml($mostpopular_alltime, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostpopular_alltime", $rows_mostpopular_alltime);
	if (count($rows_mostpopular_alltime) > 0) {
		$starttab_mostpopular_alltime = $pane->startPanel(_HWDVIDS_MPAT, 'panel1' );
		$smartyvs->assign("print_mpat", 1);
		$smartyvs->assign("starttab_mostpopular_alltime", $starttab_mostpopular_alltime);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostpopular_alltime', $hwdvids_params);
		}
	}
}

if ($hwdvids_params['showmftd'] == 1) {
	$mostfavoured_today = $parser->parse("mostfavoured_today");
	if ($hwdvids_params['style'] !== 1 && count($mostfavoured_today) > 0) {
		array_splice($mostfavoured_today, $hwdvids_params['novtd']);
	}
	$rows_mostfavoured_today = hwd_vs_tools::generateVideoListFromXml($mostfavoured_today, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostfavoured_today", $rows_mostfavoured_today);
	if (count($rows_mostfavoured_today) > 0) {
		$starttab_mostfavoured_today = $pane->startPanel(_HWDVIDS_MFTD, 'panel1' );
		$smartyvs->assign("print_mftd", 1);
		$smartyvs->assign("starttab_mostfavoured_today", $starttab_mostfavoured_today);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostfavoured_today', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmftw'] == 1) {
	$mostfavoured_thisweek = $parser->parse("mostfavoured_thisweek");
	if ($hwdvids_params['style'] !== 1 && count($mostfavoured_thisweek) > 0) {
		array_splice($mostfavoured_thisweek, $hwdvids_params['novtd']);
	}
	$rows_mostfavoured_thisweek = hwd_vs_tools::generateVideoListFromXml($mostfavoured_thisweek, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostfavoured_thisweek", $rows_mostfavoured_thisweek);
	if (count($rows_mostfavoured_thisweek) > 0) {
		$starttab_mostfavoured_thisweek = $pane->startPanel(_HWDVIDS_MFTW, 'panel1' );
		$smartyvs->assign("print_mftw", 1);
		$smartyvs->assign("starttab_mostfavoured_thisweek", $starttab_mostfavoured_thisweek);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostfavoured_thisweek', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmftm'] == 1) {
	$mostfavoured_thismonth = $parser->parse("mostfavoured_thismonth");
	if ($hwdvids_params['style'] !== 1 && count($mostfavoured_thismonth) > 0) {
		array_splice($mostfavoured_thismonth, $hwdvids_params['novtd']);
	}
	$rows_mostfavoured_thismonth = hwd_vs_tools::generateVideoListFromXml($mostfavoured_thismonth, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostfavoured_thismonth", $rows_mostfavoured_thismonth);
	if (count($rows_mostfavoured_thismonth) > 0) {
		$starttab_mostfavoured_thismonth = $pane->startPanel(_HWDVIDS_MFTM, 'panel1' );
		$smartyvs->assign("print_mftm", 1);
		$smartyvs->assign("starttab_mostfavoured_thismonth", $starttab_mostfavoured_thismonth);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostfavoured_thismonth', $hwdvids_params);
		}
	}
}
if ($hwdvids_params['showmfat'] == 1) {
	$mostfavoured_alltime = $parser->parse("mostfavoured_alltime");
	if ($hwdvids_params['style'] !== 1 && count($mostfavoured_alltime) > 0) {
		array_splice($mostfavoured_alltime, $hwdvids_params['novtd']);
	}
	$rows_mostfavoured_alltime = hwd_vs_tools::generateVideoListFromXml($mostfavoured_alltime, $hwdvids_params['thumb_width'], $hwdvids_params['mod_hwd_itemid'], $tooltip, $hwdvids_params['trunc_title'], $hwdvids_params['trunc_descr']);
	$smartyvs->assign("rows_mostfavoured_alltime", $rows_mostfavoured_alltime);
	if (count($rows_mostfavoured_alltime) > 0) {
		$starttab_mostfavoured_alltime = $pane->startPanel(_HWDVIDS_MFAT, 'panel1' );
		$smartyvs->assign("print_mfat", 1);
		$smartyvs->assign("starttab_mostfavoured_alltime", $starttab_mostfavoured_alltime);
		if ($hwdvids_params['style'] == 1) {
			hwdvsCarousel::setup('mostfavoured_alltime', $hwdvids_params);
		}
	}
}

$smartyvs->assign("hwdvids_params", $hwdvids_params);
$smartyvs->assign("static_width", ((100/$hwdvids_params['novpr'])));

$smartyvs->display('mod_hwd_vs_xml_datalists.tpl');
return;
?>
